%::PROVIDES=(
	name	=> ["GETVALIDNODES","SETVALIDNODES","ISVALID"],
	desc	=> ["Get Application valid nodes",
		    "Set Application valid nodes",
		    "Check Application valid nodes"],
	type	=> "request",
	code	=> \&::do_handle_validnodes
);

sub ::do_handle_validnodes {
my $args=shift;
my $cmdname=$args->{"_CMDNAME"};
my $app;

	if(!exists($args->{APP})) {
		logwarn("$cmdname request missing APP argument");
		return "MISSING_ARG";
	}

	$app=$args->{APP};
	if(!exists($appmap->{$app})) {
		logwarn("Specified application is not registered");
		return "NOT_REGISTERED";
	}
	if($cmdname eq "GETVALIDNODES") {
		if(!exists($appmap->{$app}->{VALIDNODES})) {
			$appmap->{$app}->{VALIDNODES}=hostname.",$OTHER_NODE_NAME";
			return "OK ".hostname.",$OTHER_NODE_NAME";
		}
		return "OK ".$appmap->{$app}->{VALIDNODES};
	}
	if($cmdname eq "SETVALIDNODES") {
		if(!exists($args->{NODES})) {
			$args->{NODES}=hostname.",$OTHER_NODE_NAME";
		}
		my ($n1,$n2)=split(/,/,$args->{NODES});
		if(defined($n1)) {
			if($n1 ne hostname && $n1 ne $OTHER_NODE_NAME) {
				return "NO_SUCH_NODE $n1";
			}
		}
		if(defined($n2)) {
			if($n2 ne hostname && $n2 ne $OTHER_NODE_NAME) {
				return "NO_SUCH_NODE $n2";
			}
		}
		$appmap->{$app}->{VALIDNODES}=$args->{NODES};
		if(exists($args->{FORWARD})) {
			queue_it("SETVALIDNODES app=$app nodes=".$args->{NODES});
		}
		return "OK";
	}
	if($cmdname eq "ISVALID") {
		#########################################################
		# Work out whether local node is a valid node to run	#
		# this application.					#
		#########################################################
		my $x=hostname;
		if(scalar(grep {/^$x$/} (split(/,/,$appmap->{$app}->{VALIDNODES})))) {
			return "YES";
		}
		return "NO";
	}
}

1;
